package main

import (
	"log"

	"gitee.com/kobeyyf/apibox/api"
	subapp "gitee.com/kobeyyf/apibox/api/test/sub_app"
	"gitee.com/kobeyyf/apibox/handler"
	"gitee.com/kobeyyf/apibox/logger"
	"gitee.com/kobeyyf/apibox/middleware/example"
)

var (
	logger *fastlog.Logger
)

func main() {
	app, err := api.NewAPI("config/config.yaml")
	if err != nil {
		log.Println(err)
		return
	}
	logger = app.GetLogger()

	app.AddHandles(map[string]handler.HandlerFunc{
		"Say.Hello": ActionSayHello,
		"Sleep.Sec": ActionSleepSec,
		"Socket":    ActionWebSocket,
	})

	app.Before(example.Example)

	subApp, err := subapp.NewApp()
	if err != nil {
		logger.Errorln(err)
		return
	}
	app.AddHandleApi(subApp)
	app.Run()
	return
}
